package utils

import (
	"gin-bms/global"
	"os"

	"go.uber.org/zap"
)

/**
 * @description: PathExists
 * @function: PathExists
 * @param {string} path
 * @return {*}
 */
func PathExists(path string) (bool, error) {
	_, err := os.Stat(path)
	if err == nil {
		return true, nil
	}
	if os.IsNotExist(err) {
		return false, nil
	}
	return false, err
}

/**
 * @description: CreateDir
 * @function: CreateDir
 * @param {...string} dirs
 * @return {*}
 */
func CreateDir(dirs ...string) (err error) {
	for _, v := range dirs {
		exist, err := PathExists(v)
		if err != nil {
			return err
		}
		if !exist {
			global.GLOBAL_LOG.Debug("create directory" + v)
			err = os.MkdirAll(v, os.ModePerm)
			if err != nil {
				global.GLOBAL_LOG.Error("create directory"+v, zap.Any(" error:", err))
			}
		}
	}
	return err
}
